est clear

use "${datadir}\expectation_appreciation_data", replace

*------------------------------------------------------------------------------*
* Regressions with full sample *
*------------------------------------------------------------------------------*

/* reg */
foreach var in fractionpositive fraction5orhigher {
	eststo `var'_full1:  areg `var' appreciation1 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm

	eststo `var'_full2:  areg `var' appreciation2 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm
		
	eststo `var'_full3:  areg `var' fut_appreciation1 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm

	eststo `var'_full4:  areg `var' fut_appreciation2 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm
		
	eststo `var'_full13:  areg `var' appreciation1 fut_appreciation1 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm

	eststo `var'_full24:  areg `var' appreciation2 fut_appreciation2 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm
}
	

*------------------------------------------------------------------------------*
* Graphs and regressions with full sample after collapse at the region - year level *
*------------------------------------------------------------------------------*


collapse (mean) fractionpositive fraction5orhigher appreciation1 ///
	appreciation2 appreciation3 appreciation5 ///
	fut_appreciation1 fut_appreciation2 (first) regionname , by(datem areacode)

/* reg */
foreach var in fractionpositive fraction5orhigher {
	eststo `var'_region1:  areg `var' appreciation1  i.datem, abs(areacode)  cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm

	eststo `var'_region2:  areg `var' appreciation2  i.datem, abs(areacode)  cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm
	
	eststo `var'_region3:  areg `var' fut_appreciation1  i.datem, abs(areacode)  cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm

	eststo `var'_region4:  areg `var' fut_appreciation2  i.datem, abs(areacode)  cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm
	
	eststo `var'_region13:  areg `var' appreciation1 fut_appreciation1 i.datem, abs(areacode) cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm

	eststo `var'_region24:  areg `var' appreciation2 fut_appreciation2 i.datem, abs(areacode)  cluster(regionname)
		estadd local year 	"Yes"
		estadd local region "Yes"
		estadd ysumm
}


*------------------------------------------------------------------------------*
* Combined table *
*------------------------------------------------------------------------------*


esttab fractionpositive_full2 fraction5orhigher_full2 ///
		fractionpositive_region2 fraction5orhigher_region2 ///
		fractionpositive_region1 fraction5orhigher_region1 ///
		fractionpositive_full22 fraction5orhigher_full22 ///
		fractionpositive_region22 fraction5orhigher_region22 ///
		fractionpositive_region11 fraction5orhigher_region11 ///
		using "${tabledir}\extrapolative_app_la_revisioncombined.tex", se b(2) ///
	keep(appreciation2 appreciation1 fut_appreciation2 fut_appreciation1) ///
	order(appreciation2 appreciation1 fut_appreciation2 fut_appreciation1) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	coeflabel(	appreciation2		"\textsc{Past appreciation (2 years)}" ///
				appreciation1		"\textsc{Past appreciation (1 year)}" ///
				fut_appreciation2 "\textsc{Future appreciation (2 years)}" ///
				fut_appreciation1 "\textsc{Future appreciation (1 year)}") ///
	stats(year region ymean ysd r2 N, fmt (0 0 2 2 2 %7.0fc) ///
	labels( `"\textsc{Year-Semester f.e.}"' `"\textsc{Local authority f.e.}"' ) ) ///
	mtitles("\textsc{>0}" "\textsc{$\geq$5\%}" ///
			"\textsc{>0}" "\textsc{$\geq$5\%}" ///
			"\textsc{>0}" "\textsc{$\geq$5\%}" ///
			"\textsc{>0}" "\textsc{$\geq$5\%}" ///
			"\textsc{>0}" "\textsc{$\geq$5\%}" ///
			"\textsc{>0}" "\textsc{$\geq$5\%}" ) replace ///
	mgroups("Individual level" "Local authority level" "Individual level" "Local authority level", pattern(1 0 1 0 0 0 1 0 1 0 0 0) ///
	prefix(\multicolumn{@span}{c}{) suffix(}) span ) /// 
	nogap nonotes